package com.kin.rich.dao;

import java.util.Date;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.kin.rich.pojo.Searchdata;

/**
 * A data access object (DAO) providing persistence and search support for
 * Searchdata entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.kin.rich.pojo.Searchdata
 * @author MyEclipse Persistence Tools
 */

public class SearchdataDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(SearchdataDAO.class);
	// property constants
	public static final String WORD_ID = "wordId";
	public static final String DATA_PAGE_NO = "dataPageNo";
	public static final String DATA_INDEX_NO = "dataIndexNo";
	public static final String DATA_TITLE = "dataTitle";
	public static final String DATA_CONTENT = "dataContent";
	public static final String DATA_SOURCE = "dataSource";
	public static final String LINK_URL = "linkUrl";
	public static final String BAIDU_CACHE = "baiduCache";
	public static final String DATA_CAT = "dataCat";
	public static final String USER_CHECKED = "userChecked";
	public static final String SEARCH_TIMES = "searchTimes";

	protected void initDao() {
		// do nothing
	}

	public void save(Searchdata transientInstance) {
		log.debug("saving Searchdata instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Searchdata persistentInstance) {
		log.debug("deleting Searchdata instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Searchdata findById(java.lang.Integer id) {
		log.debug("getting Searchdata instance with id: " + id);
		try {
			Searchdata instance = (Searchdata) getHibernateTemplate().get(
					"com.kin.rich.pojo.Searchdata", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Searchdata instance) {
		log.debug("finding Searchdata instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Searchdata instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Searchdata as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByWordId(Object wordId) {
		return findByProperty(WORD_ID, wordId);
	}

	public List findByDataPageNo(Object dataPageNo) {
		return findByProperty(DATA_PAGE_NO, dataPageNo);
	}

	public List findByDataIndexNo(Object dataIndexNo) {
		return findByProperty(DATA_INDEX_NO, dataIndexNo);
	}

	public List findByDataTitle(Object dataTitle) {
		return findByProperty(DATA_TITLE, dataTitle);
	}

	public List findByDataContent(Object dataContent) {
		return findByProperty(DATA_CONTENT, dataContent);
	}

	public List findByDataSource(Object dataSource) {
		return findByProperty(DATA_SOURCE, dataSource);
	}

	public List findByLinkUrl(Object linkUrl) {
		return findByProperty(LINK_URL, linkUrl);
	}

	public List findByBaiduCache(Object baiduCache) {
		return findByProperty(BAIDU_CACHE, baiduCache);
	}

	public List findByDataCat(Object dataCat) {
		return findByProperty(DATA_CAT, dataCat);
	}

	public List findByUserChecked(Object userChecked) {
		return findByProperty(USER_CHECKED, userChecked);
	}

	public List findBySearchTimes(Object searchTimes) {
		return findByProperty(SEARCH_TIMES, searchTimes);
	}

	public List findAll() {
		log.debug("finding all Searchdata instances");
		try {
			String queryString = "from Searchdata";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Searchdata merge(Searchdata detachedInstance) {
		log.debug("merging Searchdata instance");
		try {
			Searchdata result = (Searchdata) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Searchdata instance) {
		log.debug("attaching dirty Searchdata instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Searchdata instance) {
		log.debug("attaching clean Searchdata instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static SearchdataDAO getFromApplicationContext(ApplicationContext ctx) {
		return (SearchdataDAO) ctx.getBean("SearchdataDAO");
	}
}